package com.hc.dfs.handle;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.hc.dfs.activity.ManageActivity;
import com.hc.dfs.activity.R;

/**
 * @author 王洪胜 E-mail:
 * @version 创建时间：2013-2-19 下午2:02:03
 * 
 *          类说明：处理viewPager各分页功能
 * 
 */
public class ManageTab implements OnScrollListener {
	public View view;
	public ManageActivity mainActivity;
	public GetSignData dataList = null;
	private ListView listView;
	private Context context;
//	private int firstItem, lastItem;

	// 构造函数，传入view对应XML文件的资源ID，已经viewPager的上下文环境
	public ManageTab(int layoutId, Context context) {
		view = LayoutInflater.from(context).inflate(layoutId, null);
		// 强制转换获取Activity
		mainActivity = (ManageActivity) context;
		// 获取listView控件
		listView = (ListView) this.view.findViewById(R.id.list);
		// 缓存主界面的context
		this.context = context;
	}

	// 获取View
	public View getView() {
		return this.view;
	}
	
	// 装载适配器
	public void setMyAdapter(int pageId) {

		// 通过SimpleAdapter把填充完数据的ArrayList中的数据装载到设定的布局文件的相应位置
		SimpleAdapter listAdapter = new SimpleAdapter(mainActivity,
				mainActivity.getListItem(), R.layout.manage_list_item, new String[] {
						"miji", "huanji", "title", "date", "leixing" }, new int[] {
						R.id.imageView1, R.id.imageView2, R.id.textView1,
						R.id.textView3 , R.id.doctype});
		// 给listView装载数据
		listView.setAdapter(listAdapter);
	}

	// 给listView绑定监听器
	public void setListener(int pageId) {
		// 给listView绑定item监听器
		listView.setOnItemClickListener(new ManageTabItem(context, pageId));
		listView.setOnItemLongClickListener(new ManageTabItem(context, pageId));
		listView.setOnCreateContextMenuListener(new ManageTabItem(context, pageId));
	}

	// ArrayList获取数据方法
//	private ArrayList<HashMap<String, Object>> getData(int pageId) {
//		dataList = new GetSignData(pageId);
//		// 定义新的ArrayList
//		ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
//		// 循环设定要获取的特定数目的HashMap，并往HashMap中添加数据
//		for (int i = dataList.getDataList().size() -1; i >= 0; i--) {
//			HashMap<String, Object> map = new HashMap<String, Object>();
//			//公文id
//			int docId = dataList.getDataList().get(i).getDocument().getId();
//			//公文类型id
//			int docType = dataList.getDataList().get(i).getDocument().getDocTypeId();
//			//公文类型
//			String doctype = "["+getDocType(docType)+"]";
//			// 公文缓急
//			int h = setHuanji(dataList.getDataList().get(i).getDocument().getPriorityLevel());
//			// 公文密级
//			int m = setMiji(dataList.getDataList().get(i).getDocument().getConfidenceLevel());
//			// 公文标题
//			String t = dataList.getDataList().get(i).getDocument().getTitle();
//			// 公文日期
//			Date date = dataList.getDataList().get(i).getDocument().getSaveTime();
//			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//			String d = df.format(date);
//			// 添加数据
//			map.put("title", t);
//			map.put("date", d);
//			map.put("huanji", h);
//			map.put("miji", m);
//			map.put("leixing", doctype);
//			map.put("docId", docId);
//			map.put("docType", docType);
//			listItem.add(map);
//		}
//		// 返回数据
//		return listItem;
//	}
	
	// 获取当前系统年月日
	// public static String getDate() {
	// final Calendar c = Calendar.getInstance();
	// String date;
	// date = c.get(Calendar.YEAR) + "/" + c.get(Calendar.MONTH) + "/"
	// + c.get(Calendar.DAY_OF_MONTH);
	// return date;
	// }
	
	//根据公文类型id查询公文类型
	public String getDocType(int i){
		switch (i) {
		case 4:
			return "呈批单";
		case 5:
			return "发文稿纸";
		case 6:
			return "合同";
		default:
			return "";
		}
	}
	
	// 根据标识设置密级
	public int setMiji(int i) {
		int r = 0;
		switch (i) {
		case 1:
			r = R.drawable.miji_putong;
			break;
		case 2:
			r = R.drawable.miji_mimi;
			break;
		case 3:
			r = R.drawable.miji_jimi;
			break;
		case 4:
			r = R.drawable.miji_juemi;
			break;
		default:
			break;
		}
		System.out.println("密级标志："+i);
		return r;
	}

	// 根据标识设置缓急
	public int setHuanji(int i) {
		int r = 0;
		switch (i) {
		case 1:
			r = R.drawable.huanji_teji;
		case 2:
			r = R.drawable.huanji_jijian;
			break;
		case 3:
			r = R.drawable.huanji_pingjian;
			break;
		default:
			break;
		}
		System.out.println("缓急标志："+i);
		return r;
	}

	@Override
	public void onScrollStateChanged(AbsListView view, int scrollState) {
		// TODO Auto-generated method stub
	}

	@Override
	public void onScroll(AbsListView view, int firstVisibleItem,
			int visibleItemCount, int totalItemCount) {
		// TODO Auto-generated method stub
	}

}
